package com.dfrz.bookstore.util;

import javax.swing.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 类功能描述:
 *       正则表达式工具类
 * @Author keyan
 * @Date 2021/5/29 1:09
 */
public class RegularUtiles {

    /*校验邮箱*/
    public static boolean regEmail(String emailStr){
        String check = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern regex  = Pattern.compile(check);
        Matcher matcher = regex.matcher(emailStr);
        if (!matcher.matches()){
            JOptionPane.showMessageDialog(null,"邮箱格式错误");
            return false;
        }
        return true;
    }
    /*校验手机号码*/
    public static boolean regPhone(String Phone){
        String check = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$";
        Pattern regex  = Pattern.compile(check);
        Matcher matcher = regex.matcher(Phone);
        if ( !matcher.matches()){
            JOptionPane.showMessageDialog(null,"号码格式错误");
            return false;
        }
        return true;
    }

    /*年龄校验*/
    public static boolean regAge(int age){
        if (age<=0&&age>=130){
            JOptionPane.showMessageDialog(null,"年龄错误");
            return false;
        }
        return true;
    }


}
